package cn.pconline.activity.util;

public class JsonResult {
    private int code;
    private String message;
    private String result;
    private String callback;
    
    public JsonResult() {
        this.callback = "";
    }
    
    public JsonResult(String callback) {
        this.callback = callback;
    }
    
    public void setCode(int code) {
        this.code = code;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public void setMessage(int code,String message) {
        this.code = code;
        this.message = message;
    }
    
    public void setResult(String result) {
        this.result = result;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public String getResult() {
        return result;
    }

    @Override
    public String toString(){
        String outPut = "";
        if(!isBlank(result)){
            outPut = result;
        }else if(!isBlank(message)){
            outPut = "{\"code\":"+code+",\"message\":\""+message+"\"}";
        }else{
            outPut = "{\"code\":"+code+"}";
        }
        if(isBlank(callback)){
            return outPut;
        }else{
            return callback+"("+outPut+");";
        }
    }
    
    private static boolean isBlank(String str) {
        return (str == null || str.trim().length() == 0);
    }
}
